package org.penguin.study.bk.mq.receiver;

import lombok.extern.slf4j.Slf4j;
import org.penguin.study.bk.config.RabbitMqConfig;
import org.penguin.study.bk.mq.model.RabbitQueue1Message;
import org.penguin.study.bk.mq.model.RabbitQueue2Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * @author chengyinghua
 */
@Slf4j
@Component
@ConditionalOnProperty(name = "rabbitmq.enable", havingValue = "true")
public class ReceiverConsumer {

    private CountDownLatch latch = new CountDownLatch(1);

    @RabbitListener(queues = RabbitMqConfig.queue1Name)
    public void receiverQueue1Message(RabbitQueue1Message message) {
        log.info("收到RabbitMQ消息({}): {}", RabbitMqConfig.queue1Name, message);
    }

    @RabbitListener(queues = RabbitMqConfig.queue2Name)
    public void receiverQueue2Message(RabbitQueue2Message message) {
        log.info("收到RabbitMQ消息({}): {}", RabbitMqConfig.queue2Name, message);
    }

    public CountDownLatch getLatch() {
        return latch;
    }
}
